﻿<!--*************************************************************************************

   Toolkit for WPF

   Copyright (C) 2007-2016 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license 

   For more features, controls, and fast professional support,
   pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/

   Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids

  ************************************************************************************-->
<local:DemoView x:Class="Xceed.Wpf.Toolkit.LiveExplorer.Samples.PropertyGrid.Views.PropertyGridCustomEditorsView"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:local="clr-namespace:Xceed.Wpf.Toolkit.LiveExplorer"
                xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
                xmlns:sys="clr-namespace:System;assembly=mscorlib"
                xmlns:col="clr-namespace:System.Collections;assembly=mscorlib"
                VerticalScrollBarVisibility="Disabled"
                Title="Using EditorTemplateDefinition">
    <local:DemoView.Description>
        <Paragraph FontSize="14" FontFamily="Segoe">
            This example demonstrates the various methods of assigning custom editors to the properties. You can supply your own editor DataTemplate based on a Type, a property name, or both. To supply your own editor for a property, you must create an EditorDefinition for the PropertyGrid.
        </Paragraph>
    </local:DemoView.Description>

   <Grid>
      <Grid.RowDefinitions>
         <RowDefinition Height="Auto" />
         <RowDefinition Height="*" />
      </Grid.RowDefinitions>

      <StackPanel Grid.Row="0" Margin="10">
         <TextBlock Text="Click each property and look at the description to understand why the property is affected by a custom DataTemplate."
                    TextWrapping="Wrap"/>
         <TextBlock Text="(CLick the XAML and Code tabs to see details.)" 
                    FontStyle="Italic"
                    Margin="0,10,0,0"/>
      </StackPanel>
      <xctk:PropertyGrid x:Name="_propertyGrid" Grid.Row="1" 
                         Width="450" MaxHeight="375" Margin="10"
                         SelectedObject="{Binding}">
            <xctk:PropertyGrid.EditorDefinitions>

               <!--  EditorTemplateDefinition #1
               This EditorTemplateDefinition will provide a green TextBox to:
               1) All properties of type Double
               Replacing the default editor. -->
               <xctk:EditorTemplateDefinition TargetProperties="{x:Type sys:Double}">
                  <xctk:EditorTemplateDefinition.EditingTemplate>
                     <DataTemplate>
                        <TextBox Background="Green"  Text="{Binding Value}" />
                        <!-- 
                        When using SelectedObject[s] bind to the "Value" property 

                        When using PropertiesSource or Properties to specify your items,
                        your DataContext will be the item itself, so bind directly to the 
                        property of your underlying item, hence, probably the same path as 
                        the one you specified on the 'PropertyValueBinding'
                        property of your property grid.
                        -->
                     </DataTemplate>
                  </xctk:EditorTemplateDefinition.EditingTemplate>
               </xctk:EditorTemplateDefinition>

               <!--  EditorTemplateDefinition #2
               This EditorTemplateDefinition will provide a yellow TextBox to:
               1) The property named "LastName"
               2) The property named "FirstName"
               3) The property named "Spouse"
               Replacing the default editor. -->
               <xctk:EditorTemplateDefinition TargetProperties="FirstName,LastName,WritingFont">
                  <xctk:EditorTemplateDefinition.EditingTemplate>
                     <DataTemplate>
                        <TextBlock Background="Yellow" Text="{Binding Value}" />
                     </DataTemplate>
                  </xctk:EditorTemplateDefinition.EditingTemplate>
               </xctk:EditorTemplateDefinition>

               <!--  EditorTemplateDefinition #3
               This EditorTemplateDefinition will provide a red TextBox to:
               1) The property named "Age"
               2) All properties of type DateTime
               Replacing the default editor. -->
               <xctk:EditorTemplateDefinition >
                  <xctk:EditorTemplateDefinition.TargetProperties>
                     <sys:String>Age</sys:String>
                     <xctk:TargetPropertyType Type="{x:Type sys:DateTime}" />
                  </xctk:EditorTemplateDefinition.TargetProperties>
                  <xctk:EditorTemplateDefinition.EditingTemplate>
                     <DataTemplate>
                        <TextBox Background="Red" Text="{Binding Value}" />
                     </DataTemplate>
                  </xctk:EditorTemplateDefinition.EditingTemplate>
               </xctk:EditorTemplateDefinition>

               <!--  EditorTemplateDefinition #4
               This EditorTemplateDefinition will provide a aquamarine TextBox to:
               1) All properties of type "bool" (Boolean)
               2) All properties of type HorizontalAlignment
               3) All properties of type FontFamily
               Replacing the default editor. -->
               <xctk:EditorTemplateDefinition >
                  <xctk:EditorTemplateDefinition.TargetProperties>
                     <xctk:TargetPropertyType Type="{x:Type sys:Boolean}" />
                  <xctk:TargetPropertyType Type="{x:Type HorizontalAlignment}" />
                  <xctk:TargetPropertyType Type="{x:Type FontFamily}" />
               </xctk:EditorTemplateDefinition.TargetProperties>
                  <xctk:EditorTemplateDefinition.EditingTemplate>
                     <DataTemplate>
                        <TextBox Background="Aquamarine" Text="{Binding Value}" />
                     </DataTemplate>
                  </xctk:EditorTemplateDefinition.EditingTemplate>
               </xctk:EditorTemplateDefinition>

            </xctk:PropertyGrid.EditorDefinitions>
         </xctk:PropertyGrid>
   </Grid>
</local:DemoView>
